<?php
/**
 * feed actions.
 *
 * @package    IPLIFE
 * @subpackage feed
 * @author     Alexey Shapran alexey.shapran@gmail.com
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class feedActions extends sfActions
{
	public function executeIndex(sfWebRequest $request)
	{
		$feed = new sfRss201Feed();
		$feed->initialize(array(
				'title'=>sfConfig::get('app_title'),
				'description'=>'IPLIFE.com.ua | Интернет и телекоммуникации в Украине',
				'link'=>'http://iplife.com.ua',
				'authorEmail'=>'info@iplife.com.ua',
				'authorName'=>sfConfig::get('app_title').' Администрация'
			));

		$feedImage = new sfFeedImage();
		$feedImage->setImage('http://iplife.com.ua/images/logo.jpg');
		$feedImage->setLink('http://iplife.com.ua');
		$feedImage->setTitle(sfConfig::get('app_title'));
		$feed->setImage($feedImage);
		
		//Add news to feed
		$news = News::getLastNews(50);
		if (!empty($news))
			foreach ($news as $news_item) {
				$item = new sfFeedItem();
				$item->initialize(array(
						'title'=>$news_item->getTitle(),
						'link'=>$this->generateUrl('news_view',$news_item,true),
						'pubDate'=>$news_item->getUpdatedAt(),
						'description'=>$news_item->getShort(),
					));
				
					$enclosure = new sfFeedEnclosure();
					$enclosure->initialize(array(
							'url'=>'http://iplife.com.ua/uploads/news/thumbnail_70_70/'.$news_item->getImage()
						));
					$info = getimagesize('http://iplife.com.ua/uploads/news/thumbnail_70_70/'.$news_item->getImage());
    				$enclosure->setMimeType(image_type_to_mime_type($info[2]));

				$item->setEnclosure($enclosure);
		
				$feed->addItem($item);
			}

		//Add articles to feed
		$articles = Article::getLastArticles(50);
		if(!empty($articles))
			foreach ($articles as $article) {
				$item = new sfFeedItem();
				$item->initialize(array(
						'title'=>$article->getTitle(),
						'link'=>$this->generateUrl('article_view',$article,true),
						'pubDate'=>$article->getUpdatedAt(),
						'description'=>$article->getShort(),
					));
				
					$enclosure = new sfFeedEnclosure();
					$enclosure->initialize(array(
							'url'=>'http://iplife.com.ua/uploads/articles/thumbnail_70_70/'.$article->getImage()
						));
					$info = getimagesize('http://iplife.com.ua/uploads/articles/thumbnail_70_70/'.$article->getImage());
    				$enclosure->setMimeType(image_type_to_mime_type($info[2]));
					
				$item->setEnclosure($enclosure);
		
				$feed->addItem($item);
			}
		
		$this->feed = $feed;
	}
}
